from django.forms import ModelForm
from mac import models
from mac.forms import bootstrapform


class DepartmentAddForm(bootstrapform.BootStrapForm, ModelForm):
    class Meta:
        model = models.Department
        fields = '__all__'
        exclude = None
        labels = {
            'department_code': '部门代码',
            'department_name': '部门名称',
            'jurisdiction': '权限'
        }


class DepartmentEditForm(ModelForm):
    class Meta:
        model = models.Department
        fields = '__all__'
        exclude = None
        labels = {
            'department_code': '部门代码',
            'department_name': '部门名称',
            'jurisdiction': '权限'
        }

    def __new__(cls, *args, **kwargs):
        for field_name in cls.base_fields:  # 字段都包含在了cls.base_fields中
            filed_obj = cls.base_fields[field_name]
            # 添加属性
            filed_obj.widget.attrs.update({'class': 'form-control'})
        return ModelForm.__new__(cls)


